package mapper;

import com.yh.javabean.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Auther: Liang
 * @Date: 2024/5/9 - 05 - 09 - 9:48
 * @Description: mapper
 * @version: 1.0
 */
//使用注解实现二级缓存@CacheNamespace等价于<cache>标签
@CacheNamespace
public interface PermissionMapper {
    // List<Permission>selectAll();
    //可以使用 @Param() 注解 实现 参数的动态绑定(自定义参数获取的名称)
    List<Permission> selectByPidAndUrl(@Param("pid") int pid, @Param("url") String url);

    //基础的添加语句注解
    @Insert("insert into permission (url,`desc`) values (#{url},#{desc})")
    //mybatis通过注解的形式获取自增主键
    //@Options代表当前配置额外的属性
    //  @Options(useGeneratedKeys = true,keyProperty="pid",keyColumn="pid")

    //mybatis注解通过selectKey的形式获取自增主键
    //@SelectKey代表selectKey标签 通过对应的配置获取自增主键

    @SelectKey(statement = " SELECT LAST_INSERT_ID()  as pid", keyColumn = "pid", keyProperty = "pid", before = false, resultType = int.class)
    int insertPermission(Permission permission);

    //基础的删除语句注解
    @Delete("delete from permission where pid=#{pid}")
    int deleteByPid(int pid);

    //基础的修改语句注解
    @Update("update permission set url=#{url} where pid=#{pid} ")
    int updateUrlByPid(@Param("pid") int pid, @Param("url") String url);

    //基础查询语句注解
    @Select("select * from permission")
    List<Permission> selectAll();


    @Select("select rp.rid,p.* from permission p,role_permission rp where p.pid=rp.pid and rp.rid=#{rid}")
    List<Permission> selectByRid(int rid);

}
